package Testclass.vueTest;

import Dao.JdbcTools3;
import Model.VueStu;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

@WebServlet("/vueStud")
public class VueTestdel extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
        resp.setContentType("application/json");
        Integer did = Integer.valueOf(req.getParameter("id"));
        System.out.println(did);
//        JSONObject jsonObject = JSONObject.parseObject(did.toString());
//        Integer id1 = Integer.valueOf(jsonObject.getString("id"));
        int del = JdbcTools3.del("delete from vuestu where id=?", did);
//        String s = JSON.toJSONString(del);
        PrintWriter writer = resp.getWriter();
        if (del>0){
            System.out.println(del);

            writer.write("success");
        }else {
            writer.write("error");
        }

        writer.flush();
        writer.close();
    }
}
